package com.example.eurekacaller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@SpringBootApplication
@EnableDiscoveryClient
@RestController
@RequestMapping("/")
public class EurekacallerApplication {


    @Autowired
    private DiscoveryClient discoveryClient;

    @RequestMapping("get")
    public String getClintNames(){
        List<String> services = discoveryClient.getServices ();
        if (services.size () == 0) {
            return "no client";
        }
        StringBuilder sb = new StringBuilder ();
        services.stream ().forEach (s->sb.append (","+s));
        return sb.toString ().substring (1);
    }

    public static void main(String[] args) {
        SpringApplication.run (EurekacallerApplication.class, args);
    }

}
